home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / xcmd / sprtxtrn.sea / Support Tools eXternals 1.2.5 / card_16849.txt < prev    next >
Text File  |  1990-11-13  |  9KB  |  287 lines

  1. -- card: 16849 from stack: in.5
  2. -- bmap block id: 18713
  3. -- flags: 0000
  4. -- background id: 3858
  5. -- name: LocalVolumeList
  6. ----- HyperTalk script -----
  7. on CloseCard
  8.   put empty into cd fld "volumes"
  9.   set the scroll of cd fld "volumes" to 0
  10.   pass CloseCard
  11. end CloseCard
  12.  
  13. on HideObjects
  14.   hide cd fld "volumes"
  15.   hide cd btn "All Volumes"
  16.   hide cd btn "Local Volumes"
  17. end HideObjects
  18.  
  19. on ShowObjects
  20.   show cd fld "volumes"
  21.   show cd btn "All Volumes"
  22.   show cd btn "Local Volumes"
  23. end ShowObjects
  24.  
  25.  
  26. -- part 1 (button)
  27. -- low flags: 00
  28. -- high flags: A002
  29. -- rect: left=128 top=298 right=326 bottom=236
  30. -- title width / last selected line: 0
  31. -- icon id / first selected line: 0 / 0
  32. -- text alignment: 1
  33. -- font id: 0
  34. -- text size: 12
  35. -- style flags: 8192
  36. -- line height: 16
  37. -- part name: Local Volumes
  38. ----- HyperTalk script -----
  39. on mouseUp
  40.   global errGlobal
  41.   set cursor to watch
  42.   put LocalVolumeList("noDialog:errGlobal") into volInfo
  43.   if errGlobal Γëá empty then
  44.     answer "Error: ΓÇ£" & errGlobal & "ΓÇ¥"
  45.     put empty into errGlobal
  46.   else
  47.     put volInfo into cd fld "volumes"
  48.   end if
  49. end mouseUp
  50.  
  51.  
  52.  
  53.  
  54. -- part 2 (button)
  55. -- low flags: 00
  56. -- high flags: A002
  57. -- rect: left=18 top=298 right=326 bottom=126
  58. -- title width / last selected line: 0
  59. -- icon id / first selected line: 0 / 0
  60. -- text alignment: 1
  61. -- font id: 0
  62. -- text size: 12
  63. -- style flags: 0
  64. -- line height: 16
  65. -- part name: All Volumes
  66. ----- HyperTalk script -----
  67. on mouseUp
  68.   global errGlobal
  69.   set cursor to watch
  70.   put VolumeList("", "noDialog:errGlobal") into volInfo
  71.   if errGlobal Γëá empty then
  72.     answer "Error: ΓÇ£" & errGlobal & "ΓÇ¥"
  73.     put empty into errGlobal
  74.   else
  75.     put volInfo into cd fld "volumes"
  76.   end if
  77. end mouseUp
  78.  
  79.  
  80. -- part 3 (field)
  81. -- low flags: 00
  82. -- high flags: 0007
  83. -- rect: left=19 top=117 right=288 bottom=236
  84. -- title width / last selected line: 0
  85. -- icon id / first selected line: 0 / 0
  86. -- text alignment: 0
  87. -- font id: 4
  88. -- text size: 9
  89. -- style flags: 0
  90. -- line height: 12
  91. -- part name: Volumes
  92.  
  93.  
  94. -- part contents for background part 38
  95. ----- text -----
  96. 27/50
  97.  
  98. -- part contents for background part 20
  99. ----- text -----
  100. An XFCN which returns a carraige return delimited list of all locally mounted volumes - in other words non server volumes.
  101.  
  102. LocalVolumeList(["noDialog:"errorGlobal])
  103.   
  104.      It correctly reports floppy drives and SCSI drives (traditional Hard drives, SyQuest drives, and CD-ROM drives) as local volumes.   I have written it so that it should correctly report a Mac XL internal HD or HD20 as a local volume, but I haven't been able to test it.
  105.  
  106.  
  107. -- part contents for background part 42
  108. ----- text -----
  109. unit LocalVolumeList;
  110. {}
  111. {  brought to you by:  Anup Murarka      Eric Carlson    }
  112. {            ALINK:  SKEPTIC      ALINK:  cyNic  }
  113. {                  CIS:  76004,3356    }
  114. {}
  115. {        We are part of the Support Tools Development Group,  }
  116. {        Apple Computer, Inc.   }
  117. {}
  118. {        please DO NOT contack Mac DTS for support of this code!  }
  119. {}
  120. {        please DO contact the authors for support of this code!  }
  121. {}
  122. {        Send comments, bug reports, requests to any of the above  }
  123. {        E-mail addresses or to:}
  124. {}
  125. {              (one of us)          }
  126. {              Apple Computer, Inc.     }
  127. {              900 E. Hamilton, Ave.    }
  128. {              Campbell, CA   95008    }
  129. {              M/S 72-L          }
  130. {}
  131. {  Copyright:  ┬⌐ 1989, 1990 by Apple Computer, Inc., all rights reserved.  }
  132. {}
  133. { written by Eric Carlson                    }
  134. { AppleLink:  cyNic                        }
  135. { modification history                      }
  136. {       Date        Initials                  Comments              }
  137. {       ----        ------  ------------------------------------------------------}
  138. {    5/3/90      ec       first written                            }
  139. {}
  140.  
  141. interface
  142.  
  143.   uses
  144.     HyperXCmd;
  145.  
  146.   procedure MAIN (paramPtr: XCmdPtr);
  147.  
  148. implementation
  149.  
  150.   type
  151.     VCBPtr = ^VCB;
  152.  
  153.   procedure reportToUser (paramPtr: XCmdPtr;
  154.                   msgStr: str255);
  155. {}
  156. { report something back to the user.  }
  157. { the last parameter (optional) to an external may contain }
  158.  { "noDialog" or "noDialog:GlobalName".  GlobalName is the name }
  159.  { of a HyperTalk global variable into which error messages will be }
  160.  { placed.  we've decided to use this approach to avoid confusing }
  161. { an error message with a valid result being returned from an XFCN. }
  162. {}
  163.     var
  164.       tempStr: str255;
  165.   begin
  166. {check the last param to see if the user requested that}
  167. { we suppress the error dialog }
  168.     ZeroToPas(paramPtr, paramPtr^.params[paramPtr^.paramCount]^, tempStr);
  169.     UprString(tempStr, true);
  170.     if pos('NODIALOG', tempStr) = 0 then
  171.   { no special error handling specified, throw up a dialog and return the error message }
  172.       begin
  173.         SendCardMessage(paramPtr, concat('answer "', msgStr, '"'));
  174.         paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  175.       end
  176.     else if (pos(':', tempStr) > 0) then
  177.   { requested global AND noDialog so we fill in the global and return empty }
  178.       begin
  179.         tempStr := copy(tempStr, pos(':', tempStr) + 1, length(tempStr));
  180.                             { get the name of the HC global  to fill }
  181.         SetGlobal(paramPtr, tempStr, PasToZero(paramPtr, msgStr));
  182.                             { and fill it }
  183.         paramPtr^.returnValue := PasToZero(paramPtr, '');  { return empty }
  184.       end
  185.     else
  186.   { requested noDialog only so we return the error condition as the result }
  187.       paramPtr^.returnValue := PasToZero(paramPtr, msgStr);
  188.   end;  { procedure }
  189.  
  190.   function AskedForHelp (paramPtr: XCmdPtr;
  191.                   syntaxMsg: Str255;
  192.                   copyrightMsg: Str255): boolean;
  193. {  check to see if the user sent a '?' or a '!' as }
  194. { the only parameter. if so we will respond with }
  195. { the calling syntax or the copyright/version info }
  196. { for this external }
  197. {}
  198.     var
  199.       firstStr: str255;
  200.   begin
  201.     askedForHelp := false;
  202.     if paramPtr^.paramCount = 1 then
  203.       begin
  204.         ZeroToPas(paramPtr, paramPtr^.params[1]^, firstStr);
  205.           { what is the first param? }
  206.         if firstStr = '?' then
  207.           begin
  208.             reportToUser(paramPtr, syntaxMsg);
  209.             askedForHelp := true
  210.           end  { asked for help }
  211.         else if firstStr = '!' then
  212.           begin
  213.             reportToUser(paramPtr, copyRightMsg);
  214.             askedForHelp := true
  215.           end;  { asked for copyright info }
  216.       end;  { one parameter passed }
  217.   end;  { function }
  218.  
  219.   function AppendString (hndl: Handle;
  220.                   newStr: Str255): OSErr;
  221. {}
  222. { stick the string onto the back of the handle }
  223. {}
  224.   begin
  225.     AppendString := PtrAndHand(Ptr(ORD4(@newStr) + 1), hndl, LENGTH(newStr));
  226.   end;
  227.  
  228.   procedure LocalVolumeList (paramPtr: XCmdPtr);
  229.     var
  230.       volList: handle;
  231.       err: OSErr;
  232.       aQueElement: VCBPtr;
  233.       headPtr: QHdrPtr;
  234.       unitTableSlot: integer;
  235.  
  236.   begin
  237.     if askedForHelp(paramPtr, 'LocalVolumeList(<ΓÇ£noDialog:ΓÇ¥errorGlobal>)', 'v1.0, ┬⌐1990 Apple Computer ,Inc,  Eric Carlson . ') then
  238.       exit(LocalVolumeList);
  239.  
  240.     volList := NewHandle(0);    { use a handle for the list in case someone has more that 255 chars worth of drives }
  241.     err := MemError;        { handle allocated OK? }
  242.     if err <> noErr then
  243.       begin
  244.         reportToUser(paramPtr, 'Out of memory.');
  245.         exit(LocalVolumeList);
  246.       end;
  247.  
  248.     headPtr := GetVCBQHdr;      { grab the vcb que header }
  249.     if headPtr <> nil then
  250.       begin
  251.         aQueElement := VCBPtr(headPtr^.qHead);
  252.         while aQueElement <> nil do  { now step through all of the VCB entries }
  253.           begin
  254.             unitTableSlot := BITNOT(aQueElement^.vcbDRefNum);        { the unit table entry number, IM IV-215 }
  255.             if (unitTableSlot in [32..39]) or (unitTableSlot = 4) or (unitTableSlot = 1) then
  256.               begin  { entry numbers 32-39 are for SCSI drivers 0-7, entry number 4 is for Sony driver (floppy), }
  257.           { entry number 1 is for a Mac XL internal or HD20 }
  258.                 err := AppendString(volList, concat(aQueElement^.vcbVN, chr(13)));  { remember the volume name }
  259.                 if err <> noErr then
  260.                   begin
  261.                     reportToUser(paramPtr, 'Out of memory.');
  262.                     if volList <> nil then
  263.                       DisposHandle(volList);
  264.                     exit(LocalVolumeList);
  265.                   end;
  266.               end;
  267.             aQueElement := VCBPtr(aQueElement^.qLink);
  268.           end;
  269.       end;    { VCB ptr <> nil }
  270.  
  271.     if volList <> nil then
  272.       begin
  273.         SetHandleSize(volList, GetHandleSize(volList) - 1);    { drop the trailing comma }
  274.         err := AppendString(volList, chr(0));    { Terminate with 0 byte  }
  275.         if err <> noErr then
  276.           reportToUser(paramPtr, 'Out of memory.');
  277.       end;
  278.     paramPtr^.returnValue := volList;
  279.   end;    { procedure LocalDiskList}
  280.  
  281.   procedure MAIN (paramPtr: XCmdPtr);
  282.   begin
  283.     LocalVolumeList(paramPtr);
  284.   end;
  285.  
  286.  
  287. end.  { unit FileExists}